<script setup lang="ts">
import DoctorCard from './DoctorCard.vue'

import { doctor } from '../composable/home-navs'
import { viewAdapter } from '@/composable'

const { doctorList } = doctor()

const { itemWidth } = viewAdapter()

function onLikeDoctor(id: string) {
  const index = doctorList.value.findIndex((el) => el.id === id)
  doctorList.value[index].likeFlag = +!doctorList.value[index].likeFlag as 0 | 1
}
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <van-swipe
        :width="itemWidth"
        class="my-swipe"
        :loop="false"
        :show-indicators="false"
      >
        <van-swipe-item v-for="doctor in doctorList" :key="doctor.id">
          <DoctorCard
            :doctor="doctor"
            @like-doctor="() => onLikeDoctor(doctor.id)"
          />
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
